//
//  XQNetworkMonitor.swift
//  Spark Peso
//
//  Created by 小琦 on 2025/2/16.
//

import Network

class XQNetworkMonitor {
    
    static let shared = XQNetworkMonitor()
    private var monitor: NWPathMonitor?
    private var isMonitoring = false

    private init() {}

    func startMonitoring(completion: @escaping (Bool) -> Void) {
        guard !isMonitoring else { return }
        
        monitor = NWPathMonitor()
        monitor?.pathUpdateHandler = { path in
            if path.status == .satisfied {
                completion(true)
            }else {
                completion(false)
            }
        }
        
        let queue = DispatchQueue(label: "Monitor")
        monitor?.start(queue: queue)
        isMonitoring = true
    }

    func stopMonitoring() {
        monitor?.cancel()
        monitor = nil
        isMonitoring = false
    }
    
}
